package com.design.movieticket.controller;

import com.design.movieticket.common.base.constant.Result;
import com.design.movieticket.common.base.constant.ResultStatus;
import com.design.movieticket.entity.Balance;
import com.design.movieticket.entity.Recharge;
import com.design.movieticket.service.BalanceService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.math.BigDecimal;

@Slf4j
@Api(tags = "余额模块")
@RestController
@RequestMapping("/balance")
public class BalanceController {
    @Resource
    private BalanceService balanceService;

    @GetMapping("/getBalanceByUserId")
    public Result getBalanceByUserId(Long userId){
        return new Result(balanceService.getBalanceByUserId(userId), ResultStatus.REQUEST_SUCCESS.getMsg(),ResultStatus.REQUEST_SUCCESS.getCode());
    }

    @PostMapping("/wxRecharge")
    public Result wxRecharge(@RequestBody Recharge recharge){
        System.out.println(recharge);
        String username = recharge.getUsername();
        Long userId = recharge.getUserId();
        BigDecimal money = recharge.getRechargeMoney();
        return new Result(balanceService.wxRecharge(username,userId,money),ResultStatus.REQUEST_SUCCESS.getMsg(),ResultStatus.REQUEST_SUCCESS.getCode());
    }
}
